//
//  NSDictionary+Extend.m
//  XLDoctor
//
//  Created by longma on 2018/12/27.
//  Copyright © 2018年 XLH. All rights reserved.
//

#import "NSString+Extend.h"

@implementation NSString (Extend)

- (NSDictionary *)mj_stringConvertToDictionary{
    if (self == nil) {
        return nil;
    }
    NSData *jsonData = [self dataUsingEncoding:NSUTF8StringEncoding];
    NSError *err;
    NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&err];
    if(err) {
        NSLog(@"json解析失败：%@",err);
        return nil;
    }
    return dic;
}
- (NSArray *)mj_stringConvertToArray{
    if (self == nil) {
        return nil;
    }
    NSData *jsonData = [self dataUsingEncoding:NSUTF8StringEncoding];
    NSError *err;
    NSArray *array = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&err];
    if(err) {
        NSLog(@"json解析失败：%@",err);
        return nil;
    }
    return array;
}

/*判断字符串是否为空*/
+ (BOOL) isNullString:(id)string
{
    if(string == nil)
    {
        return YES;
    }
    if( [string isEqual:[NSNull null]] ){
        
         return YES;
    }
    else if(string == [NSNull null])
    {
        return YES;
    }
    else if([string isKindOfClass:[NSNull class]])
    {
        return YES;
    }
    else if([string isEqualToString:@"(null)"])
    {
        return YES;
    }
    else if([string isEqualToString:@"<null>"])
    {
        return YES;
    }
    else if([[string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length] == 0)
    {
        return YES;
    }
    else
    {
        return NO;
    }
}

- (NSString *)mj_stringByPreviousString:(NSString *)preString LaterString:(NSString *)laterString{
    NSRange preRan = [self rangeOfString:preString];
    NSRange latRan = [self rangeOfString:laterString];
    
    NSRange subRan = NSMakeRange(preRan.location + 1, latRan.location - preRan.location - 1);
    
    NSString *subString = [self substringWithRange:subRan];
    return subString;
}
@end
